export default function modal(obj){
    let app = document.getElementById('app') ,
        modal = document.getElementById('modal');
    if(modal) modal.parentNode.removeChild(modal);
    let modalEle = document.createElement('div');
    modalEle.id = 'modal';
    modalEle.className = 'modalWrap flex-container';
    modalEle.innerHTML = '<div class="modal-inner">' +
                              '<h3>' + ( obj.title ? obj.title : '' ) + '</h3>' +
                              '<div class="modal-cot">' + obj.content + '</div>' +
                              '<div class="modal-btns flex-container">' +
                                (obj.ensure ? '<a href="javascript:;" id="modalSure">确定</a>' : '') +
                                (obj.cancel ? '<a href="javascript:;" id="modalCancel">取消</a>' : '') +
                              '</div>' +
                          '</div>';
    app.appendChild(modalEle);
    if(!document.getElementById('modalSure')) return;
    document.getElementById('modalSure').onclick = function(){
        document.getElementById('modal').parentNode.removeChild(document.getElementById('modal'));
       obj.ensure();
    };
    if(!document.getElementById('modalCancel')) return;
    document.getElementById('modalCancel').onclick = function(){
        document.getElementById('modal').parentNode.removeChild(document.getElementById('modal'));
        obj.cancel();
    }
}
